package com.tsingtree.config.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.tsingtree.modular.enums.CommonStatusEnum;

import java.util.Objects;

/**
 * Excel 性别转换器
 *
 * @author william@StarImmortal
 */
public class StatusConverter implements Converter<Integer> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }


    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) {
        Integer value = context.getValue();
        if(Objects.isNull(value)){
            return new WriteCellData<>();
        }
        String str = CommonStatusEnum.getAll().get(value);
        return new WriteCellData<>(str);
    }
}
